package com.example.demo.controller;

import com.example.demo.entity.Book;
import com.example.demo.service.BookService;
import com.example.demo.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "书籍接口")
@RestController
@RequestMapping("/api/book")
public class BookController {

    @Autowired
    private BookService bookService;

    @ApiOperation(httpMethod = "POST", value = "书籍列表", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @RequestMapping(method = RequestMethod.POST, value = "/list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object list() {

        List<Book> list = bookService.list();
        return ResultUtil.success(list);
    }

    @ApiOperation(httpMethod = "POST", value = "根据书籍编码查询书籍详情", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @RequestMapping(method = RequestMethod.POST, value = "/getByNum/{num}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object getByNum(@PathVariable("num") String num) {

        Book book = bookService.getByNum(num);
        return ResultUtil.success(book);
    }


}
